package com.tianji.learning.mq;

import com.tianji.api.dto.LikedTimesDTO;
import com.tianji.common.constants.MqConstants;
import com.tianji.learning.domain.po.InteractionReply;
import com.tianji.learning.service.IInteractionReplyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * TODO
 *
 * @Author whx
 * @Date 2025/1/3 15:30
 */
@Component
@Slf4j
public class LikedTimesListener {

    @Autowired
    private IInteractionReplyService interactionReplyService;

    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange(value = MqConstants.Exchange.LIKE_RECORD_EXCHANGE, type = ExchangeTypes.TOPIC),
            value = @Queue(value = MqConstants.Queue.LIKED_TIMES_QUEUE),
            key = MqConstants.Key.LIKED_TIMES_KEY
    ))
    public void asyncLikedTimes(LikedTimesDTO dto){
        log.info("交换机接收到业务发来的消息！！！");
        InteractionReply r = new InteractionReply();
        r.setId(dto.getBizId());
        r.setLikedTimes(dto.getLikedTimes());
        interactionReplyService.updateById(r);
    }

}
